/**
*@note Copyright 2012-2022 CETHIK All Rights Reserved.
*@brief 数据处理类文件 
*@author tuyinan
*@data 2022-04-xx
*/
#ifndef COSTMAP_2D_OBSERVATION_BUFFER_H_
#define COSTMAP_2D_OBSERVATION_BUFFER_H_

#include <config_file.h>
#include <costmap_2d/costmap_math.h>
#include <costmap_2d/msg_struct.h>
#include <costmap_2d/observation.h>

#include <Eigen/Eigen>
#include <list>
#include <string>
#include <vector>

// Thread support
#include <boost/thread.hpp>

namespace costmap_2d {
/**
*@brief 点云数据处理类
*@author tuyinan
*@version 2022-04-xx
*/
class ObservationBuffer {
 public:
/**
*@brief 构造函数
*@param ConfigFile* configNode 配置节点
*@return void
*@author: tuyinan
*@version: 2022-04-xx
*/
  ObservationBuffer(ConfigFile* configNode);

/**
*@brief 析构函数
*@param 无
*@return void
*@author: tuyinan
*@version: 2022-04-xx
*/
  ~ObservationBuffer();

/**
*@brief 处理点云数据
*@param costmap_2d::PointCloud* cloud 点云数据
*@param Eigen::Transform<float, 3, Eigen::Isometry> transform 转换矩阵
*@param costmap_2d::Point origin 机器人位姿
*@return void
*@author: tuyinan
*@version: 2022-04-xx
*/
  void bufferCloud(costmap_2d::PointCloud* cloud,
                   Eigen::Transform<float, 3, Eigen::Isometry> transform,
                   costmap_2d::Point origin);

/**
*@brief 获取处理后的数据
*@param std::vector<Observation>& observations 处理后的数据集
*@return void
*@author: tuyinan
*@version: 2022--xx
*/
  void getObservations(std::vector<Observation>& observations);

/**
*@brief 判断是否数据最新
*@param 无
*@return bool 是或否
*@author: tuyinan
*@version: 2022-04-xx
*/
  bool isCurrent() const;

/**
*@brief 上锁
*@param 无
*@return void
*@author: tuyinan
*@version: 2022-04-xx
*/
  inline void lock() { lock_.lock(); }

/**
*@brief 解锁
*@param 无
*@return void
*@author: tuyinan
*@version: 2022-04-xx
*/
  inline void unlock() { lock_.unlock(); }

/**
*@brief 重置记载的时间
*@param 无
*@return void
*@author: tuyinan
*@version: 2022-04-xx
*/
  void resetLastUpdated();

 private:
/**
*@brief 清除过时数据
*@param 无
*@return void
*@author: tuyinan
*@version: 2022-04-xx
*/
  void purgeStaleObservations();

  /// 配置节点
  ConfigFile* configNode_;
  /// 观察持续时间
  double observation_keep_time_;
  /// 更新频率
  double expected_update_rate_;
  /// 上次更新的时间
  time_t last_updated_;
  /// 数据列表
  std::list<Observation> observation_list_;
  /// 障碍物最小和最高值
  double min_obstacle_height_, max_obstacle_height_;
  /// 一把小锁
  boost::recursive_mutex
      lock_;  ///< @brief A lock for accessing data in callbacks safely
  /// 障碍物范围和激光范围
  double obstacle_range_, raytrace_range_;
};
}  // namespace costmap_2d
#endif  // COSTMAP_2D_OBSERVATION_BUFFER_H_
